//https://leetcode.cn/problems/minimum-number-of-frogs-croaking/description/
class Solution {
    public int minNumberOfFrogs(String croakOfFrogs) {
        char[] s = croakOfFrogs.toCharArray();
        int[] hash = new int[26];
        for (int i = 0; i < s.length; i++) {
            if (s[i] == 'c') {
                if (hash['k' - 'a'] != 0) hash['k' - 'a']--;
                hash['c' - 'a']++;
            } else if (s[i] == 'r') {
                if (hash['c' - 'a']-- == 0) return -1;
                hash['r' - 'a']++;
            } else if (s[i] == 'o') {
                if (hash['r' - 'a']-- == 0) return -1;
                hash['o' - 'a']++;
            } else if (s[i] == 'a') {
                if (hash['o' - 'a']-- == 0) return -1;
                hash['a' - 'a']++;
            } else if (s[i] == 'k') {
                if (hash['a' - 'a']-- == 0) return -1;
                hash['k' - 'a']++;
            }
        }
        if (hash['c' - 'a'] != 0 || hash['r' - 'a'] != 0 ||
                hash['o' - 'a'] != 0 || hash['a' - 'a'] != 0) return -1;
        return hash['k' - 'a'];
    }
}